package studio.servletsala;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


import studio.excepcion.DAOExcepcion;
import studio.modelo.Administrador;
import studio.negocio.SeguridadSala;

/**
 * Servlet implementation class ServRegSala
 */
public class ServRegSala extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServRegSala() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("123");
		
		int idLocal =Integer.parseInt(request.getParameter("local"));
		String nomSala = request.getParameter("nomsala");
		int capacidad  =Integer.parseInt(request.getParameter("capacidad"));
		String caracte  = request.getParameter("caracte");
		double precio=Double.parseDouble(request.getParameter("precio"));
		//precio
		PrintWriter out=response.getWriter();
		out.println(idLocal);
		out.println(nomSala);
		out.println(capacidad);
		out.println(caracte);
		SeguridadSala NegSala=new SeguridadSala();
		
		HttpSession sesion = request.getSession();
		Administrador obj=(Administrador)sesion.getAttribute("Admin_Actual");
		 try {
			 String ms="";
			ms= NegSala.insertarSala(idLocal, nomSala, capacidad, caracte,obj.getIdUsuario(),precio);
			//response.sendRedirect(request.getContextPath() + "/ListadoSala.jsp");
			request.getSession().setAttribute("msg", ms);
			request.getSession().setAttribute("ruta", "RegistrarSala.jsp");
			RequestDispatcher rd=request.getRequestDispatcher("/mensaje.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
